class Solution
{
public:
    int movesToMakeZigzag(vector<int> &nums)
    {
        int n = nums.size();
        int oddDecrease = 0;
        int evenDecrease = 0;
        for (int i = 0; i < n; ++i)
        {
            if (i & 1)
            {
                int left = nums[i - 1];
                int right = (i + 1 < n) ? nums[i + 1] : INT_MAX;
                oddDecrease += max(0, max(nums[i] - left + 1, nums[i] - right + 1));
            }
            else
            {
                int left = i > 0 ? nums[i - 1] : INT_MAX;
                int right = (i + 1 < n) ? nums[i + 1] : INT_MAX;
                evenDecrease += max(0, max(nums[i] - left + 1, nums[i] - right + 1));
            }
        }
        return min(oddDecrease, evenDecrease);
    }
};